package com.souche.employment.controller;

import com.souche.employment.domain.DepartmentDO;
import com.souche.employment.mapper.DepartmentMapper;
import com.souche.employment.mapper.JobMapper;
import com.souche.employment.response.DataResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;

/**
 * BaseController.java created at 2017年8月8日 下午1:11:20
 *
 * @author Ray [email:rayinhangzhou@hotmail.com]
 * Revision History
 * Date            Programmer                   Notes
 * ----------------------------------------------------------
 **/

@RestController
@RequestMapping(value = "/dep")
@Api(value = "/dep", description = "部门接口")
public class DepartmentController {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Autowired
    private JobMapper jobMapper;


    @RequestMapping(value = "/getDepsForList", method = RequestMethod.GET)
    @ApiOperation(value = "获取部门筛选列表")
    public DataResult getDepsForList(@RequestParam(required = false) String level,
                                     @RequestParam(required = false) String father) {
        List<DepartmentDO> list = departmentMapper.findDeps(level, father);
        if (list == null) {
            return DataResult.success(new LinkedHashMap<>());
        }
        LinkedHashMap<String, String> result = new LinkedHashMap<>();
        list.stream().forEach(DepartmentDO -> result.put(DepartmentDO.getId(), DepartmentDO.getName()));
        return DataResult.success(result);
    }


}
